//
//  SINAStuHomeCoursItemModel.m
//  sinashebao
//
//  Created by  androidlongs on 2018/1/16.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "SINAStuHomeCoursItemModel.h"
#import "SINAStuActivityTargetModel.h"
#import "SINAStuActivityImpressModel.h"

@implementation SINAStuHomeCoursItemModel


-(instancetype)initWithDict:(NSDictionary *)result{
    if (self=[super init]) {
        //[NSString stringWithFormat:@"%@",result[@"name"]];
        _itemId=[NSString stringWithFormat:@"%@",result[@"id"]];
        _courseUid=[NSString stringWithFormat:@"%@",result[@"uuid"]];
        _activityUid=[NSString stringWithFormat:@"%@",result[@"uuid"]];
        // 1是课程 2 是活动
        _itemType=[NSString stringWithFormat:@"%@",result[@"itemtype"]];
        
        
        _partneruuid = result[@"partneruuid"];
        
        //课程名称
        _courseTitle=result[@"coursename"];
        //课程开始时间
        _courseStartTime=result[@"starttime"];
        //课程结束时间
        _courseEndTime=result[@"endtime"];
        //课程地点
        _courseLocation=result[@"address"];
        //课程表 课程 uuid
        _courseSyUid=result[@"syuuid"];
        //课程每周上课信息uuid
        _courseUid=result[@"sacuuid"];
        _tstatus=result[@"tstatus"];
        
        /*
         调课后的相关数据
         "tstarttime": "1523844000000",
         "tendtime": "1523851200000",
         "taddress": "11C407",
         "status": "1000",
         */
        _tstarttime=result[@"tstarttime"];
        _tendtime=result[@"tendtime"];
        _taddress=result[@"taddress"];
        _status=result[@"status"];
        
        _tecSignStartTime =result[@"rollcalltime"];
        
        
        //经度
        _courseLocationLat=result[@"lati"];
        //纬度
        _courseLocationLon=result[@"lon"];
        //海拔
        _courseLocationHeight=result[@"height"];
        if (_courseLocationLat==nil) {
            //经度
            _courseLocationLat=result[@"tlati"];
            //纬度
            _courseLocationLon=result[@"tlon"];
        }
        
        
        _organizeuuidfordetailUid=[NSString stringWithFormat:@"%@",result[@"organizeuuidfordetail"]];
        //status 0 组队中
        //status 1 组队成功
        _itemStatue =[NSString stringWithFormat:@"%@",result[@"status"]];
        
        //活动标题
        _activityTitle =[NSString stringWithFormat:@"%@",result[@"typename"]];
        
        _activityStartTime=[NSString stringWithFormat:@"%@",result[@"starttime"]];
        _courseTime=_activityStartTime;
        _activityStopTime=[NSString stringWithFormat:@"%@",result[@"endtime"]];
        
        //地址
        _courseLocation=[NSString stringWithFormat:@"%@",result[@"address"]];
        if (_courseLocation==nil||[_courseLocation isEqualToString:@""]||[_courseLocation isEqualToString:@"(null)"]) {
            _courseLocation =@"暂无地址";
        }
        
        //活动描述
        _activityDes=[NSString stringWithFormat:@"%@",result[@"content"]];
        
        if (_activityTitle==nil||[_activityTitle isEqualToString:@""]||[_activityTitle isEqualToString:@"(null)"]) {
            _activityTitle =_activityDes;
        }
        //发起组队的人
        NSMutableArray *resultOtherArray=result[@"organizers"];
        if(resultOtherArray!=nil&&resultOtherArray.count>0){
            //活动发起组队的人
            NSMutableArray *arry2=[[NSMutableArray alloc]init];
            for (NSInteger j=0; j<resultOtherArray.count; j++) {
                NSDictionary *itemDic = resultOtherArray[j];
                SINASINAStuHomeCoursItemModel2 *userModel = [[SINASINAStuHomeCoursItemModel2 alloc]init];
                userModel.userTitleImageUrl=itemDic[@"organizerimg"];
                userModel.activityStartTime=itemDic[@"activitystarttime"];
                userModel.activityStopTime=itemDic[@"activityendtime"];
                
                userModel.activityUserUid=itemDic[@"organizeruuid"];
                userModel.activityUid=itemDic[@"activityuuid"];
                userModel.activityLocation=itemDic[@"activityaddress"];
                
                userModel.otherUserUid=itemDic[@"organizeruuid"];
                [arry2 addObject:userModel];
            }
            _otherUserList = arry2;
        }
        //想与你组队的人
        NSMutableArray *resultTeamArray=result[@"followers"];
        NSMutableArray *arry1=[[NSMutableArray alloc]init];
        if (resultTeamArray!=nil&&resultTeamArray.count>0) {
            
            for (NSInteger j=0; j<resultTeamArray.count; j++) {
                NSDictionary  *itemDic = resultTeamArray[j];
                SINASINAStuHomeCoursItemModel2 *userModel = [[SINASINAStuHomeCoursItemModel2 alloc]init];
                
                userModel.activityStartTime=itemDic[@"applystarttime"];
                userModel.activityStopTime=itemDic[@"applyendtime"];
                userModel.userTitleImageUrl=itemDic[@"followerimg"];
                
                userModel.activityLocation=itemDic[@"applyaddress"];
                
                //活动用户uuid
                userModel.activityUserUid=itemDic[@"followeruuid"];
                //活动uuid
                userModel.activityUid=itemDic[@"uuid"];
                
                
                userModel.otherUserUid=itemDic[@"organizeruuid"];
                
                [arry1 addObject:userModel];
            }
            _teamUserList = arry1;
        }
        
        _activityStatue=@"1";
        _activityShowDetaile=NO;
        
        
        _itemTime=@"8:00";
        
        
        if ([_itemType integerValue]==2&&_itemStatue!=nil&&_itemStatue.length>0) {
            if ([_itemStatue integerValue]==0) {
                // 正在组队状态
                _activityStatue=@"1";
                _activityShowDetaile=NO;
                _itemType=@"2";
                
                //活动时间
                _activityStartTime=[NSString stringWithFormat:@"%@",result[@"starttime"]];
                _courseTime=_activityStartTime;
                _activityStopTime=[NSString stringWithFormat:@"%@",result[@"endtime"]];
            }
            if ([_itemStatue integerValue]==1) {
                // 组队成功
                _activityStatue=@"2";
                _activityShowDetaile=NO;
                _itemType=@"2";
                
                //活动时间
                _activityStartTime=[NSString stringWithFormat:@"%@",result[@"finalstarttime"]];
                _courseTime=_activityStartTime;
                _activityStopTime=[NSString stringWithFormat:@"%@",result[@"finalendtime"]];
                _courseLocation=[NSString stringWithFormat:@"%@",result[@"finaladdress"]];
                
                //头像
                _activityUserImg=[NSString stringWithFormat:@"%@",result[@"partnerimg"]];
                _activityUserName=[NSString stringWithFormat:@"%@",result[@"partnername"]];
                _activityUserUid=[NSString stringWithFormat:@"%@",result[@"partneruuid"]];
            }
            
            if ([_itemStatue integerValue]==2) {
                // 组队完成
                _activityStatue=@"3";
                _activityShowDetaile=NO;
                _itemType=@"2";
                
                
                _activityUserImg=[NSString stringWithFormat:@"%@",result[@"partnerimg"]];
                _activityUserName=[NSString stringWithFormat:@"%@",result[@"partnername"]];
                _activityUserUid=[NSString stringWithFormat:@"%@",result[@"partneruuid"]];
                
                //小目标
                NSArray *targets =result[@"targets"];
                NSMutableArray *targetArray = [[NSMutableArray alloc]init];
                for (NSInteger i=0; i<targets.count; i++) {
                    NSDictionary *dic = targets[i];
                    SINAStuActivityTargetModel *targetModel = [[SINAStuActivityTargetModel alloc]initWithDict:dic];
                    [targetArray addObject:targetModel];
                }
                
                _teamTargetArray = targetArray;
                
                //随笔
                NSArray *essays =result[@"essays"];
                
                NSMutableArray *essayArray = [[NSMutableArray alloc]init];
                for (NSInteger i=0; i<essays.count; i++) {
                    NSDictionary *dic = essays[i];
                    SINAStuActivityImpressModel *impressModel = [[SINAStuActivityImpressModel alloc]initWithDict:dic];
                    [essayArray addObject:impressModel];
                }
                _teamImpressionArray = essayArray;
            }
        }
        //活动地址
        _activityLocation = _courseLocation;
        
    }
    return self;
}
+(instancetype)userWithDict:(NSDictionary *)dict{
    return [[self alloc] initWithDict:dict];
}
@end
